package com.jiandaoshou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jiandaoshou.R;
import com.jiandaoshou.entry.OrderDetailInfo;

import java.util.List;

/**
 * Created by Administrator on 2016/12/24 0024.
 */

public class OrderAdapter extends BaseAdapter {
    private Context context;
    private List<OrderDetailInfo> list;
    public OrderAdapter(Context context,List<OrderDetailInfo> list) {
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public OrderDetailInfo getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView == null) {
            holder=new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_order_item, parent, false);
            holder.tvName = (TextView) convertView.findViewById(R.id.detail_name);
            holder.tvNum = (TextView) convertView.findViewById(R.id.detail_ordernum);
            holder.tvPrice = (TextView) convertView.findViewById(R.id.detail_orderprice);
            convertView.setTag(holder);
        } else {
            holder= (ViewHolder) convertView.getTag();
        }
        OrderDetailInfo orderDetailInfo=list.get(position);
        holder.tvName.setText(String.format("%s(%s)",orderDetailInfo.getStrWaresName(),orderDetailInfo.getStrWaresNumber()));
        holder.tvNum.setText(String.format("x %s",orderDetailInfo.getnWaresCount()));
        holder.tvPrice.setText(String.format("￥%s",orderDetailInfo.getStrWaresPrice()));
        return convertView;
    }

    class ViewHolder{
        TextView tvName;
        TextView tvNum;
        TextView tvPrice;
    }

    public void setList(List<OrderDetailInfo> list) {
        this.list = list;
        notifyDataSetChanged();
    }
}
